<?php
namespace app\school\model;
use think\Model;

class SchoolCourseModel extends Model
{
    public function schoolClass()
    {
        return $this->belongsTo('SchoolClassModel', 'class_id')->setEagerlyType(1);
    }
    public function schoolLevel()
    {
        return $this->belongsTo('SchoolLevelModel', 'level_id')->setEagerlyType(1);
    }
    public function schoolSubject()
    {
        return $this->belongsTo('SchoolSubjectModel', 'subject_id')->setEagerlyType(1);
    }
    public function schoolTeacher()
    {
        return $this->belongsTo('SchoolTeacherModel', 'teacher_id')->setEagerlyType(1);
    }

    /**
     * post_content 自动转化
     * @param $value
     * @return string
     */
    public function getContentAttr($value)
    {
        return cmf_replace_content_file_url(htmlspecialchars_decode($value));
    }

    /**
     * post_content 自动转化
     * @param $value
     * @return string
     */
    public function setContentAttr($value)
    {
        return htmlspecialchars(cmf_replace_content_file_url(htmlspecialchars_decode($value), true));
    }

    public function getSignupTimeAttr($value)
    {
        return date("Y-m-d H:i",$value);
    }
    public function setSignupTimeAttr($value)
    {
        return strtotime($value);
    }

    public function getCutoffTimeAttr($value)
    {
        return date("Y-m-d",$value);
    }
    public function setCutoffTimeAttr($value)
    {
        return strtotime($value);
    }
    
    public function lists($parmas)
    {
        if(!empty($parmas['subject_id'])){
            $where['subject_id'] = $parmas['subject_id'];
        }
        if(!empty($parmas['class_id'])){
            $where['class_id'] = $parmas['class_id'];
        }
        if(!empty($parmas['teacher_id'])){
            $where['teacher_id'] = $parmas['teacher_id'];
        }
        if(!empty($parmas['keyword'])){
            $where['title'] = ['like','%'.$parmas['keyword'].'%'];
        }
        $where['delete_time'] = 0;
        $list = $this->order("list_order ASC")->where($where)->paginate(10);
        return $list;
    }
}